package com.smedi.ismedi.inmail.core.domain.aggregatemodel;

import lombok.*;
import org.apache.commons.lang3.StringUtils;

import java.time.LocalDateTime;

/**
 * @className: AppVersion
 * @Description: TODO
 * @version: v1.0.0
 * @author: wzx
 * @date: 2023/8/30 10:23
 */

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@EqualsAndHashCode(callSuper = false)
public class AppVersion {

    /**
     * id
     */
    private Long id;
    /**
     * 版本号
     */
    private String appVersion;

    /**
     * 版本号第一位
     */
    private String versionOne;
    /**
     * 版本号第二位
     */
    private String versionTwo;
    /**
     * 版本号第三位
     */
    private String versionThree;

    /**
     * 更新地址
     */
    private String address;
    /**
     * 更新方式
     */
    private String method;
    /**
     * 系统
     */
    private String systemType;
    /**
     * 更新内容
     */
    private String content;
    /**
     * 状态
     */
    private Boolean enable;

    private LocalDateTime updateTime;

    public void init() {
        String[] versions = StringUtils.split(this.appVersion, ".");
        this.versionOne = versions[0];
        this.versionTwo = versions[1];
        this.versionThree = versions[2];
        this.enable = false;
    }

    public String getAppVersion() {
        if (this.versionOne != null && this.versionTwo != null && this.versionThree != null) {
            return this.versionOne + "." + this.versionTwo + "." + this.versionThree;
        }
        return this.appVersion;
    }

}